package _struct

import (
	"fmt"
)

//匿名字段
type Person struct {
	string
	int
}

type Address struct {
	Province string
	City     string
}

//嵌套匿名字段，可用于继承
type User struct {
	Name   string
	Gender string
	Address
}

func TestStruct3() {
	p1 := Person{"aa", 18}
	fmt.Printf("%#v\n", p1)

	fmt.Println(p1.int)

	user1 := User{
		"xiao",
		"男",
		Address{
			"四川",
			"成都",
		},
	}
	fmt.Println(user1)
	fmt.Printf("%#v\n", user1)

	var u1 User1
	u1.Name = "uu"
	u1.Gender = "gen"
	u1.Address1 = Address1{"provice", "chengdu", "2020-01-01"}
	u1.Email1 = Email1{"sina.com", "2020-01-02"}

	u1.Address1.CreateTime = ""
	fmt.Println(u1)
}

//Address 地址结构体
type Address1 struct {
	Province   string
	City       string
	CreateTime string
}

type Email1 struct {
	Account    string
	CreateTime string
}

//User 用户结构体
type User1 struct {
	Name   string
	Gender string
	Address1
	Email1
}

//继承
type Animal struct {
	name string
}

func (a Animal) move() {
	fmt.Printf("%s会动！\n", a.name)
}

type Dog struct {
	Feet int8
	Animal
}

func (d Dog) wang() {
	fmt.Printf("%s会汪汪汪~\n", d.name)
}

func TestInherit() {
	d1 := &Dog{4, Animal{"name"}}
	d1.wang()
	d1.move()
}
